var windowName = "liveInfo";
var Page,count=0;
apiready = function(){

    onWindowShow(function () {
        console.log(windowName + " show")
        if (count > 0) {
            getData(Page)
            checkPayed(Page)
        }
        count++
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        //页面数据
        curTab:0
        ,id:0
        ,payStatus:0
        ,grades:{}
        ,subjects:[]
        ,teacher:{}
        ,live:{}
        ,list:[]
    },{
        //页面方法
        "init":function () {
            //先填缓存数据
            var cache= getLocData("liveInfoCache")
            if (isTrue(cache)) {
                this.teacher = cache.teacher;
                this.live = cache.live
            }

            Page.grades = getLocData("grades")
            Page.subjects = getLocData("subjects")
            var data = getData4Page()
            this.id = data.id
            getData(this)
            checkPayed(this)
        }
        ,play:function(url,title){
            var videoPlayer = api.require('videoPlayer');
            videoPlayer.play({
                texts: {
                    head: {
                        title: title
                    }
                },
                styles: {
                    head: {
                        bg: 'rgba(0,0,0,0.5)',
                        height: 24,
                        titleSize: 20,
                        titleColor: '#fff',
                        backSize: 20,
                        backImg: 'fs://img/back.png',
                        setSize: 12,
                        setImg: 'fs://img/set.png'
                    },
                    foot: {
                        bg: 'rgba(0,0,0,0.5)',
                        height: 44,
                        playSize: 24,
                        // playImg: 'fs://img/back.png',
                        // pauseImg: 'fs://img/back.png',
                        nextSize: 0,
                        // nextImg: 'fs://img/back.png',
                        timeSize: 14,
                        timeColor: '#fff',
                        sliderImg: 'fs://img/slder.png',
                        progressColor: '#696969',
                        progressSelected: '#76EE00'
                    }
                },
                path: url, //（可选项）字符串类型；文档的路径，支持网络和本地（fs://）路径；默认：未传值时不播放
                //在 android 平台上不支持 widget://
                autoPlay: true //（可选项）布尔类型；打开时是否自动播放；默认：true（自动播放）
                ,autorotation:false
            }, function(ret, err) {
                if (ret) {
                    // alert(JSON.stringify(ret));
                } else {
                    // alert(JSON.stringify(err));
                }
            });
        }
    })
    Page.init()
}


function getData(_this) {
    apiLoad("/app/getLiveInfo",{id:_this.id},function (res) {
        log(res)
        _this.teacher = res.d.teacher
        _this.live = res.d.live
        // _this.list = res.d.list
        setLocData("liveInfoCache",res.d)
    });
}


function checkPayed(_this) {
    apiGet("/app/check/payed", {id: _this.id}, function (res) {
        _this.payStatus = res.d;
    });
}